#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define LED1_PIN 4
#define LED2_PIN 5
#define LED3_PIN 15
#define BUTTON_PIN 14

void app_main(void)
{
    gpio_config_t led;
    led.pin_bit_mask = 1 << LED1_PIN | 1 << LED2_PIN | 1 << LED3_PIN;
    led.mode = GPIO_MODE_OUTPUT;
    led.pull_up_en = GPIO_PULLUP_DISABLE;
    led.pull_down_en = GPIO_PULLDOWN_DISABLE;
    led.intr_type = GPIO_INTR_DISABLE;
    gpio_config(&led);

    gpio_config_t btn;
    btn.pin_bit_mask = 1 << BUTTON_PIN;
    btn.mode = GPIO_MODE_INPUT;
    btn.pull_up_en = GPIO_PULLUP_ENABLE;
    btn.pull_down_en = GPIO_PULLDOWN_DISABLE;
    btn.intr_type = GPIO_INTR_DISABLE;
    gpio_config(&btn);

    int level = 0;

    while (1)
    {
        if (gpio_get_level(BUTTON_PIN) == 0)
        {
            vTaskDelay(pdMS_TO_TICKS(10));
            if (gpio_get_level(BUTTON_PIN) == 0)
            {
                while (gpio_get_level(BUTTON_PIN) == 0)
                    ;
                level = !level;
                gpio_set_level(LED1_PIN, level);
                gpio_set_level(LED2_PIN, level);
                gpio_set_level(LED3_PIN, level);
            }
        }
        vTaskDelay(pdMS_TO_TICKS(10));
    }
}
